home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Collection of Tools & Utilities
/
Collection of Tools and Utilities.iso
/
print
/
pgraf130.zip
/
PASCAL.ZIP
/
DEMO_SUB.PAS
< prev
next >
Wrap
Pascal/Delphi Source File
|
1991-10-14
|
25KB
|
797 lines
unit demo_sub;
{*******************************************************************
* *
* 'Printer Graphics Interface' Demonstration Program *
* Demonstration Subrotuines Module *
* *
* Main program: DEMO.PAS *
* Author: F van der Hulst *
* *
* Revisions: *
* 27 March 1991: Initial release (Turbo C v2.0 only) *
* 07 April 1991: Ported to MicroSoft C v5.1 *
* 15 October 1991: Rewritten in Turbo-Pascal *
* *
*******************************************************************}
interface
uses graph, pgraph, dos, various;
procedure shapes_demo;
procedure stroked_fonts_demo;
procedure Default_Font_demo;
procedure horiz_text_demo;
procedure vert_text_demo;
procedure text_scaling_demo;
procedure shape_Fill_demo;
procedure flood_Fill_demo;
procedure lines_demo;
procedure pie_demo;
procedure end_slice;
var page_height, page_width: integer; { Size of page in pixels }
var prn: file of char; { Output device }
var screen_echo: boolean;
implementation
const MAX_WIDTH = 801; { Maximum width of any PGRAPH viewport defined in the program }
function min(x, y: integer): integer;
begin
if (x < y)
then min := x
else min := y;
end;
function max(x, y: integer): integer;
begin
if (x > y)
then max := x
else max := y;
end;
var line_num: integer;
var FF: char;
{*******************************************************************
End of outputting a slice to the buffer. Check to see whether it will
fit on the current page. If not skip to the top of the next page }
procedure end_slice;
var
xres, yres: integer;
height: integer;
begin
p_getresolution(xres, yres);
xres := p_getmaxx;
height := p_getmaxy + 1;
line_num := line_num + height;
if (line_num > longint(yres) * page_height div 100) then begin
line_num := height;
write(prn, FF);
end;
if not screen_echo then write('Printing...');
p_print(filerec(prn).handle);
if not screen_echo then writeln;
p_cleardevice;
end;
{********************************************************************
Draw lines, ellipses, polygons, move graphics cursor }
procedure shapes_demo;
var
xasp, yasp: integer;
xres, yres: integer;
error_code: integer;
width, height: integer;
free_space: longint;
arccoords: arccoordstype;
const polypoints: array[0..13] of integer = (
500, 160,
500, 340,
450, 250,
400, 250,
350, 330,
360, 170,
500, 160);
begin
writeln; writeln;
writeln('SHAPES DEMO');
writeln;
p_getresolution(xres, yres);
p_setviewport(0, 0, 0, 0, 0);
free_space := memavail - $4000; { Leave room for other graph memory uses }
width := trunc((longint(xres) * longint(page_width)) / 100);
height := integer(free_space * 8 div width);
height := min(height, integer(longint(yres) * page_height div 100));
writeln('Setting ', width, ' by ', height, ' pixel (', width div xres,
'*', height div yres, ' inches) viewport');
p_setviewport(0, 0, width - 1, height - 1, 0);
error_code := p_graphresult;
if (error_code <> 0) or (height < 340) then writeln('Failed... Insufficient memory')
else begin
p_setlinestyle(4, $8080, 1);
p_rectangle(0, 0, p_getmaxx, p_getmaxy);
p_setlinestyle(2, 0, 1);
writeln('p_drawpoly(7, polypoints);');
p_drawpoly(7, polypoints);
writeln('p_rectangle(220, 140, 270, 10);');
p_rectangle(220, 240, 270, 110);
writeln('p_circle(p_getmaxx - 120, 100, 100);');
p_circle(p_getmaxx - 120, 100, 100);
writeln('p_arc(p_getmaxx - 220, 100, 45, 135, 100);');
p_arc(p_getmaxx - 220, 100, 45, 135, 100);
p_getarccoords(arccoords);
writeln('Last arc centred at (', arccoords.x, ', ', arccoords.y,
'), from (', arccoords.xstart, ', ', arccoords.ystart,
') to (', arccoords.xend, ', ', arccoords.yend, ')');
writeln('p_ellipse(90, 10, 0, 360, 30, 10);');
p_ellipse(90, 10, 0, 360, 30, 10);
writeln('p_ellipse(160, 10, 0, 360, 5, 10);');
p_ellipse(160, 10, 0, 360, 5, 10);
writeln('p_ellipse(200, 10, 45, 135, 30, 10);');
p_ellipse(200, 10, 45, 135, 30, 10);
writeln('p_ellipse(240, 10, 45, 135, 5, 10);');
p_ellipse(240, 10, 45, 135, 5, 10);
writeln('p_ellipse(280, 10, 45, 225, 30, 10);');
p_ellipse(280, 10, 45, 225, 30, 10);
writeln('p_getaspectratio(xasp, yasp);');
writeln('p_setaspectratio(xasp, yasp div 3);');
p_getaspectratio(xasp, yasp);
p_setaspectratio(xasp, yasp div 3);
writeln('Same circle and arc as above, but Ycentre at 390');
p_circle(p_getmaxx - 120, 390, 100);
p_arc(p_getmaxx - 220, 390, 45, 135, 100);
writeln('Width = ', p_getmaxx, ', Height = ', p_getmaxy);
writeln('Current position = (', p_getx, ', ', p_gety, ')');
writeln('p_moveto(40, 50);');
p_moveto(40, 50);
writeln('Current position = (', p_getx, ', ', p_gety, ')');
writeln('p_moverel(+20, -10);');
p_moverel(+20, -10);
writeln('Current position = (', p_getx, ', ', p_gety, ')');
writeln('Various ellipse fragments');
p_ellipse(450, 60, 0, 20, 100, 50);
p_ellipse(450, 60, 30, 60, 100, 50);
p_ellipse(450, 60, 70, 90, 100, 50);
p_ellipse(450, 60, 90, 110, 100, 50);
p_ellipse(450, 60, 120, 150, 100, 50);
p_ellipse(450, 60, 160, 180, 100, 50);
p_ellipse(450, 60, 180, 200, 100, 50);
p_ellipse(450, 60, 210, 240, 100, 50);
p_ellipse(450, 60, 250, 270, 100, 50);
p_ellipse(450, 60, 270, 290, 100, 50);
p_ellipse(450, 60, 300, 330, 100, 50);
p_ellipse(450, 60, 340, 360, 100, 50);
p_ellipse(100, 140, 20, 340, 100, 50);
writeln('Lines');
p_setlinestyle(3, 0, 1);
p_line(100, 140, 200, 140);
p_line(100, 140, 100, 90);
p_line(0, 200, 10, 250);
p_line(0, 200, 50, 210);
p_line(50, 210, 0, 220);
p_line(50, 210, 40, 250);
p_moveto(450, 60);
p_linerel(100, 0);
p_lineto(450, 110);
writeln('Pixels');
p_putpixel(319, 0, 1);
p_putpixel(319, 1, 1);
p_putpixel(319, 1, 0);
end_slice;
end;
end;
{*******************************************************************
Register stroked fonts, and print them in different sizes and
orientations }
procedure stroked_fonts_demo;
var goth_height, next_line: integer;
var errorcode: integer;
begin
writeln; writeln;
writeln('STROKED FONTS DEMO');
writeln;
p_setviewport(0, 0, 719, 170, 0);
errorcode := p_registerbgifont(@Gothic_Font);
if errorcode < 0 then begin
writeln('Couldn''t register Gothic font: ', errorcode);
halt(2);
end;
errorcode := p_registerfarbgifont(@Script_Font_far);
if errorcode < 0 then begin
writeln('Couldn''t register Script font: ', errorcode);
halt(2);
end;
writeln('Printing text size 1, horizontally');
p_settextstyle(GothicFont, HorizDir, 1);
p_outtextxy(0, 0, 'Gothic 1');
goth_height := p_textheight('Gothic 1');
p_settextstyle(ScriptFont, HorizDir, 1);
p_outtextxy(200, 0, 'Script 1');
next_line := max(p_textheight('Script 1'), goth_height);
writeln('Printing text size 1, vertically');
p_settextstyle(GothicFont, VertDir, 1);
p_outtextxy(360, 0, 'Gothic 1');
p_settextstyle(ScriptFont, VertDir, 1);
p_outtextxy(380, 0, 'Script 1');
writeln('Printing text size 2, horizontally');
p_settextstyle(GothicFont, HorizDir, 2);
p_outtextxy(0, next_line, 'Gothic 2');
goth_height := p_textheight('Gothic 2');
p_settextstyle(ScriptFont, HorizDir, 2);
p_outtextxy(200, next_line, 'Script 2');
next_line := next_line + max(p_textheight('Script 2'), goth_height);
writeln('Printing text size 2, vertically');
p_settextstyle(GothicFont, VertDir, 2);
p_outtextxy(410, 0, 'Gothic 2');
p_settextstyle(ScriptFont, VertDir, 2);
p_outtextxy(430, 0, 'Script 2');
writeln('Printing text size 3, horizont